Page({
  data: {
    boxList: [{
      id: 1,
      shop_id: 'xxx',
      open_id: 'xxx',
      status: 0,
      number1: "5",
      number2: "1",
      percent: "83"
    },
    {
      id: 2,
      shop_id: 'xxx',
      open_id: 'xxx',
      status: 1,
      number1: "5",
      number2: "1",
      percent: "83"
    }],
    windowHeight: 568,
    currentIndex: 0,
    boxImage: ''

  },
  onLoad(e) {
    my.getSystemInfo({
      success: (res) => {
        console.log(res)
        this.setData({
          windowHeight: res.windowHeight
        })
      },
    });
    this.setData({
      boxImage: e.boxImage
    })
    this.loadData();
  },
  onShareAppMessage() {
    let currentIndex = this.data.currentIndex;
    return {
      title: '你的好友邀你拆礼盒',
      desc: '帮我拆礼盒，你也能免费拿',
      path: `/pages/index/index?box_id=${this.data.boxList[currentIndex].id}&main_id=${this.data.boxList[currentIndex].open_id}&shop_id=${this.data.boxList[currentIndex].shop_id}`
    }
  },
  onSwiperChange(e) {
    this.setData({
      currentIndex: e.detail.current
    })
  },
  share() {
    my.showSharePanel();
  },
  async getBox() {
    const { cloud } = getApp();
    const res = await cloud.application.httpRequest({
      path: '/index.php/index/tb/getbox',
      method: 'GET',
      params: {
        shop_id: getApp().globalData.shop_id
      }
    });
    my.showToast({
      content: res,
      success: (res) => {
        this.loadData()
      }
    })
  },
  openBox() {
    let currentIndex = this.data.currentIndex;
    my.navigateTo({
      url: `../detail/detail?box_id=${this.data.boxList[currentIndex].id}`
    });
  },
  async loadData() {
    const { cloud } = getApp();
    const res = await cloud.application.httpRequest({
      path: '/index.php/index/tb/my',
      method: 'GET',
      params: {
        shop_id: getApp().globalData.shop_id
      }
    });
    console.log(res)
    this.setData({
      boxList: res
    })

  }
});
